﻿Public Class clsEmpresaRentaDAOvb
    Private ContextoDeObjs As New DataEntities
    Public Function Insertar(ByVal Obj As EmpresaRenta) As Boolean
        Try
            ContextoDeObjs.AddToEmpresaRenta(Obj)
            ContextoDeObjs.SaveChanges()
        Catch ex As Exception
            MsgBox(ex.InnerException.Message, MsgBoxStyle.Critical)
            Return False
        End Try
        Return True
    End Function

    Public Function Modificar(ByVal obj As EmpresaRenta) As Boolean
        Try

            ContextoDeObjs.AttachTo("EmpresaRenta", obj)
            ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified)
            ContextoDeObjs.SaveChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
            Return False

        End Try
        Return True
    End Function

    Public Function Eliminar(ByVal obj As EmpresaRenta) As Boolean
        Try
            ContextoDeObjs.AttachTo("EmpresaRenta", obj)
            ContextoDeObjs.DeleteObject(obj)
            ContextoDeObjs.SaveChanges()
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical)
            Return False
        End Try
        Return True
    End Function
    Public Function listar() As List(Of EmpresaRenta)
        Dim lista As New List(Of EmpresaRenta)()
        Dim q = From c In ContextoDeObjs.EmpresaRenta
        lista = q.ToList()
        Return lista
    End Function
End Class
